package com.dao.impl;

import com.bean.Role;
import com.dao.BaseDao;
import com.dao.RoleDao;
import com.utils.SqlUtils;

import java.util.List;
import java.util.Map;

public class RoleDaoImpl extends BaseDao implements RoleDao {

    @Override
    public List<Role> selectForPageItems(int begin, int pageSize, String content) {
        if (content == null) {
            content = "";
        }
        content = "%" + content + "%";
        String sql = SqlUtils.pageSql(Role.class,null);
        return queryForList(Role.class, sql, content, begin, pageSize);
    }

    @Override
    public Integer selectForPageTotalCount(String content) {
        if (content == null) {
            content = "";
        }
        content = "%" + content + "%";
        String sql = SqlUtils.countSql(Role.class);
        Number count = (Number) queryForSingleValue(sql, content);
        return count.intValue();
    }

    @Override
    public Role selectBy(Role role) {
        Map.Entry<String, Object[]> entry = SqlUtils.selectBy(role,null);
        return queryForOne(Role.class, entry.getKey(),entry.getValue());
    }

    @Override
    public int insert(Role role) {
        Map.Entry<String, Object[]> entry = SqlUtils.insertSql(role);
        return update(entry.getKey(), entry.getValue());
    }

    @Override
    public int deleteByPrimaryKey(Integer id) {
        String sql = "delete from `role` where `id` = ?";
        return update(sql, id);
    }

    @Override
    public int updateByPrimaryKey(Role role) {
        Map.Entry<String, Object[]> entry = SqlUtils.updateSql(role);
        return update(entry.getKey(),entry.getValue());
    }

}
